import axios from "axios";
import { Toast } from "vant";

let toast

const request = new axios.create({
    baseURL: "http://interview-api-t.itheima.net",
    timeout: 5000,
})

request.interceptors.request.use(
    function (config) {
        toast=Toast.loading({
            message: '加载中...',
            forbidClick: true,
            duration: 0,
        })
        return config
    },
    function (error) {
        return Promise.reject(error);
    },
)

request.interceptors.response.use(
    function (response) {
        toast.clear()
        return response
    },
    function (error) {
        Toast.fail(error.response.data.message)
        return Promise.reject(error);
    },
)

export default request;